package com.reportingapplication.student;

import com.reportingapplication.student.tools.ID;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.view.Menu;
import android.view.View;

/**
 * Main Activity for the Reporting App. Students can press the help button here.
 * @author Keith Davelaar
 *
 */
public class MainActivity extends Activity {
	/** Where all information is saved **/
	private SharedPreferences settings;
	
	/**
	 * Called when the application is started. Checks whether user is already registered and 
	 * sets up all class variables.
	 */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		// Get the settings for this app.
		settings = getSharedPreferences(ID.PREFS_NAME, 0);
		//Check if the user is registered.
		boolean loggedIn = settings.getBoolean(ID.LOGGED_IN, false);
		if(!loggedIn){
			// User is not registered so go to the activity to do so.
			Intent intent = new Intent(this, SignupActivity.class);
			startActivity(intent);
		}
	}

	/**
	 * Standard.
	 */
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}
	
	/**
	 * Reset screen when orientation is changed
	 */
	@Override
	public void onConfigurationChanged(Configuration config){
		super.onConfigurationChanged(config);
		setContentView(R.layout.activity_main);
		// Setup the local variables.
		settings = getSharedPreferences(ID.PREFS_NAME, 0);
	}
    
    /**
     * Called when the button report button is pressed
     */
    public void report(View view) {
    	startActivity(new Intent(this, LocationSelectionActivity.class));
    }
    
    /**
     * Called when the demo buton is pressed
     */
    public void demo(View view) {
    	startActivity(new Intent(this, DemoActivity.class));
    }
}